package Weapons;

import java.util.Random;
import game.Config.BulletFactory;

import org.newdawn.slick.geom.Vector2f;
/**
 * This class represents a Machine gun in the game. The machine gun
 * extends Weapon and can fire bullets.
 * When the machine gun fires bullets, it does not aim in a straight line, 
 * it has a recoil.
 * @author Sebastian Isheden and Victor Beer
 *
 */
public class MachineGun extends Weapon{
	protected double recoil;
	/**
	 * Creates a machine gun from given parameters.
	 * @param fireRate	The amount of times this weapon can fire per second.
	 * @param damage  The damage per shot of this weapon.
	 * @param bulletSpeed  The speed the fired bullets will traverse the screen.
	 * @param recoil The angle, given in degrees, that the machine gun will spread bullets.
	 */
	public MachineGun(float fireRate, float damage, float bulletSpeed,double recoil) {
		super(fireRate, damage, bulletSpeed);
		this.recoil = recoil;
	}
	@Override
	protected void spawnBullet(Vector2f position, Vector2f direction) {
		Random random = new Random();
		double shootOffset = random.nextDouble()*2 - 1;
		Vector2f offsetDirection = direction.copy().add(shootOffset*recoil);
		callFactory(position,offsetDirection);
	}
	protected void callFactory(Vector2f position,Vector2f direction){
		BulletFactory.createStandardBullet(this.damage,this.bulletSpeed,position,direction);
	}
	/**
	 * Returns a copy of the machine gun.
	 */	
	@Override
	public Weapon copy() {
		return new MachineGun(1/this.fireInterval,this.damage,this.bulletSpeed,this.recoil);
	}
}
